#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: currentframe.py
# Description: 
#   In addition to introspection of code objects, inspect includes functions for
#   inspecting the runtime environment while a program is running. 
#   Most of these functions work with the call stack, and operate on “call frames”. 
#   Each frame record in the stack is a 6 element tuple containing the frame object, 
#   the filename where the code exists, the line number in that file for the current 
#   line being run, the function name being called, a list of lines of context from 
#   the source file, and the index into that list of the current line. 
#   Typically such information is used to build tracebacks when exceptions are raised.
#   It can also be useful when debugging programs, since the stack frames can be 
#   interrogated to discover the argument values passed into the functions.
# Edit History: 
#   2011-11-03    File created.
#===============================================================================
import inspect

def recurse(limit):
    """
    currentframe() returns the frame at the top of the stack (for the current function). 
    getargvalues() returns a tuple with argument names, the names of the variable arguments,
    and a dictionary with local values from the frame.
    """
    local_variable = '.' * limit
    print limit, inspect.getargvalues(inspect.currentframe())
    if limit <= 0:
        return
    recurse(limit - 1)
    return

if __name__ == '__main__':
    recurse(3)
